package tcards.android;

import models.Kind;
import models.Tcard;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.text.SpannableString;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.Button;
import android.widget.FrameLayout;

public class TcardButton extends FrameLayout {
	private Button mButton;
	private Tcard mTcard;
	
	public TcardButton(Context context) {
		this(context, null, 0);
	}

	public TcardButton(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}

	public TcardButton(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		LayoutInflater li = LayoutInflater.from(context);
		addView(li.inflate(R.layout.tcard_button, this, false));
		mButton = (Button) findViewById(R.id.tcardButton);
	}	
	
	public Tcard getTcard() {
		return mTcard;
	}
	
	public void setTcard(Tcard t) {
		mTcard = t;		 
		mButton.setText(t.toDisplayString());
		mButton.setTextColor(Color.BLACK);
		mButton.setBackgroundColor(getColorForKind(t.getKind()));
	}
	
	public static int getColorForKind(int kind) {
		return getColorForKind(Kind.values()[kind]);
	}
	
	public static int getColorForKind(Kind kind) {
		switch(kind)
		{
    	case HandCrews:
    		return Color.rgb(0x35, 0xFF, 0x67);
    	case Engines:
    		return Color.rgb(0xFC, 0xA3, 0xCF);
    	case Helicopters:
    		return Color.rgb(0x77, 0x89, 0xFF);
    	case Personnel:
    		return Color.rgb(0xFF, 0xFF, 0xFF);
    	case Aircraft:
    		return Color.rgb(0xFF, 0x9D, 0x3C);
    	case HeavyEquipment:
    		return Color.rgb(0xF0, 0xFF, 0x23);
    	case Misc:
    		return Color.rgb(0xC7, 0x93, 0x76);
    	case Generic:
    		return Color.rgb(0xF6, 0xD2, 0xF6);
    	default:
    		throw new RuntimeException("No color has been defined for Kind value: " + kind.toString());
		}
	}
	
	public void setTypeface(Typeface tf) {
		mButton.setTypeface(tf);
	}
	
	public Typeface getTypeface() {
		return mButton.getTypeface();
	}
	
	public void setText(SpannableString string) {
		mButton.setText(string);
	}
	
	public CharSequence getText() {
		return mButton.getText();
	}
	
	@Override
	public void setOnTouchListener(OnTouchListener l) {
		mButton.setOnTouchListener(l);
	}
	
	@Override
	public void setOnClickListener(OnClickListener l) {
		mButton.setOnClickListener(l);
	}
	
	@Override
	public void setOnLongClickListener(OnLongClickListener l) {
		mButton.setOnLongClickListener(l);
	}
}
